import { Controller, Get, Post, Body, Patch, Param, Delete, Inject, ValidationPipe, Version, VERSION_NEUTRAL } from '@nestjs/common';
import { CccService } from './ccc.service';
import { CreateCccDto } from './dto/create-ccc.dto';
import { UpdateCccDto } from './dto/update-ccc.dto';
import { OPTIONS_TYPE, MODULE_OPTIONS_TOKEN } from './ccc.module-definition';
import { ConfigService } from '@nestjs/config';

@Controller({
  path: 'ccc',
  // version: '1'
  version: VERSION_NEUTRAL
})
export class CccController {
  // constructor(private readonly cccService: CccService, @Inject('CONFIG_OPTIONS') private configOptions: Record<string, any>) {}
  constructor(private readonly cccService: CccService) {}

  @Inject(MODULE_OPTIONS_TOKEN)
  private moduleOptions: typeof OPTIONS_TYPE

  @Inject(ConfigService)
  private configService: ConfigService

  @Post()
  create(@Body(new ValidationPipe()) createCccDto: CreateCccDto) {
    console.log(createCccDto)
    return this.cccService.create(createCccDto);
  }

  @Version('2')
  @Get()
  findAll2() {
    // console.log(this.configOptions)
    return this.cccService.findAll() + '2222';
  }

  @Get('getconfig')
  async testGetConfig() {
    return {
      db: this.configService.get('db'),
      config: this.configService.get('aaa.bbb.ccc'),
      ccc: this.configService.get('ddd')
    }
  }
  
  @Get()
  findAll() {
    // console.log(this.configOptions)
    return this.cccService.findAll();
  }

  

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.cccService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateCccDto: UpdateCccDto) {
    return this.cccService.update(+id, updateCccDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.cccService.remove(+id);
  }
}
